/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.clyme.expediente.hibernate;

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author user
 */
public class HibernateUtil {

    private static  SessionFactory sessionFactory;
    
    private HibernateUtil(){
        
    }
    private static SessionFactory init(){
        try {
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
        return sessionFactory;
    }
    
    public static SessionFactory getSessionFactory(){
        if(sessionFactory == null){
            synchronized(HibernateUtil.class){
                if(sessionFactory == null){
                    sessionFactory = init();
                }
            }
        }
        return sessionFactory;
    } 
}
